﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Persistencia;

namespace GestorDeFlotasDesktop.UILogic.Helpers
{
    /// <summary>
    /// Métodos helpers para validaciones
    /// </summary>
    public class ValidatorHelper
    {
        public static string getValue(TextBox textBox)
        {
            if (string.IsNullOrEmpty(textBox.Text))
                return null;
            else
                return textBox.Text;
        }

        public static string getText(string comboBox)
        {
            if (string.IsNullOrEmpty(comboBox))
                return null;
            else
                return comboBox;
        }

        public static Int64 getValue(TextBox textBox, Int64 defaultValue)
        {
            if (string.IsNullOrEmpty(textBox.Text))
                return defaultValue;
            else
                return Convert.ToInt64(textBox.Text);
        }

        internal static string getValue(ComboBox cmbMarca)
        {
            return getText(((ComboBoxItem)cmbMarca.SelectedItem).Value.ToString());
        }

        public static bool isStringFieldValid(String textValue)
        {
            if (!String.IsNullOrEmpty(textValue))
                return true;

            return false;
        }

        public static bool isNumericIntFieldValid(string textValue)
        {
            int number = 0;
            return int.TryParse(textValue, out number);
        }

        public static bool isNumericDoubleFieldValid(string textValue)
        {
            double number = 0;
            return double.TryParse(textValue, out number);
        }

        public static bool isNumericLongFieldValid(string textValue)
        {
            long number = 0;
            return Int64.TryParse(textValue, out number);
        }

        public static bool isListBoxFieldValid(ListBox listBox)
        {
            if (listBox.SelectedItems.Count > 0)
                return true;

            return false;
        }
    }
}
